package com.yuexun.dhdoctor.module.meetingNew.ui;

import android.content.Intent;
import android.graphics.drawable.ColorDrawable;
import android.text.TextUtils;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;

import com.yuexun.dhdoctor.R;
import com.yuexun.dhdoctor.base.BaseEntity;
import com.yuexun.dhdoctor.base.BaseKJActivity;
import com.yuexun.dhdoctor.config.AppConfig;
import com.yuexun.dhdoctor.module.meetingNew.adapter.MeetingNewRoomStateAdapter;
import com.yuexun.dhdoctor.module.meetingNew.bean.MeetingNewRoomBean;
import com.yuexun.dhdoctor.module.meetingNew.bean.MeetingNewRoomStateBean;
import com.yuexun.dhdoctor.module.meetingNew.bean.MeetingNewRoomStateOneBean;
import com.yuexun.dhdoctor.module.meetingNew.bean.MeetingRoomBean;
import com.yuexun.dhdoctor.module.meetingNew.model.impl.MeetingNewModel;
import com.yuexun.dhdoctor.module.meetingNew.presenter.impl.MeetingNewAllRoomPresenter;
import com.yuexun.dhdoctor.module.meetingNew.presenter.impl.MeetingNewRoomStatePresenter;
import com.yuexun.dhdoctor.module.meetingNew.ui.view.IMeetingNewAllRoomView;
import com.yuexun.dhdoctor.module.meetingNew.ui.view.IMeetingNewRoomStateView;
import com.yuexun.dhdoctor.widget.ActionSheetDialog;
import com.yuexun.dhdoctor.widget.LoadingDialog;
import com.yuexun.dhdoctor.widget.MeetingRoomDialog;
import com.yuexun.dhdoctor.widget.PullToRefresh.FooterLoadingLayout;
import com.yuexun.dhdoctor.widget.PullToRefresh.PullToRefreshList;
import com.yuexun.dhdoctor.widget.ToastDialog;
import com.yuexun.dhdoctor.widget.pickerUtil.CustomDatePicker;

import org.json.JSONException;
import org.json.JSONObject;
import org.kymjs.kjframe.ui.ViewInject;
import org.kymjs.kjframe.utils.PreferenceHelper;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Locale;
import java.util.Map;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by wangt on 2017/12/26.
 */

public class Act_MeetingNew_RoomUse extends BaseKJActivity implements IMeetingNewRoomStateView, IMeetingNewAllRoomView {

    @Bind(R.id.tv_date)
    TextView tvDate;
    @Bind(R.id.pull_list)
    PullToRefreshList pullList;

    @Bind(R.id.tv_room)
    TextView tvRoom;
    @Bind(R.id.tv_state)
    TextView tvState;
    @Bind(R.id.ll_type)
    LinearLayout llType;
    @Bind(R.id.tv_type)
    TextView tvType;
    @Bind(R.id.right)
    TextView right;

    public static final int INCREASE_COST_DAY = 1;
    public static final int DECREASE_COST_DAY = -1;

    private SimpleDateFormat formatter;
    private Calendar calendar = Calendar.getInstance();

    private MeetingNewRoomStatePresenter presenter;
    private MeetingNewAllRoomPresenter allRoomPresenter;

    //会议室列表
    private ArrayList<MeetingNewRoomBean> roomList = new ArrayList<>();
    //
    private ArrayList<MeetingNewRoomStateBean> meetingRooms = new ArrayList<>();
    private MeetingNewRoomStateAdapter adapter;

    //0：只能查看  1：可查看、可选择
    private int tag;
    //当前的会议室
    private String nowRoomId = "";
    //会议室状态 0：全部   1：空闲   2：占用  3：锁定
    private int nowUserFlag = 0;
    //时间类型  1：单个时间  2：连续时间
    private int nowType = 0;

    private LoadingDialog loadingDialog;

    //--------------------选择状态下数据------------------
    private MeetingNewRoomBean selectRoom;
    private String selectStartTime;
    private String selectEndTime;

    //双选模式下  选中的两个时间段
    private ArrayList<MeetingNewRoomStateOneBean> selectTimeBean = new ArrayList<>();
    //是连续时间段
    private boolean isContinuous = true;

    private MeetingRoomDialog dialog;
    private String time;

    @Override
    public void setRootView() {
        super.setRootView();
        setContentView(R.layout.act_meetingnew_roomuser);
        ButterKnife.bind(this);
    }

    @Override
    public void initData() {
        super.initData();
        tag = getIntent().getIntExtra("tag", 0);
        if (tag == 0) {
            llType.setVisibility(View.GONE);
        } else {
            llType.setVisibility(View.VISIBLE);
        }

        presenter = new MeetingNewRoomStatePresenter(new MeetingNewModel(), this);
        allRoomPresenter = new MeetingNewAllRoomPresenter(new MeetingNewModel(), this);
        loadingDialog = new LoadingDialog(this);
        loadingDialog.setCanceledOnTouchOutside(false);
        loadingDialog.setCancelable(true);

        formatter = new SimpleDateFormat("yyyy-MM-dd");
        choseCostDay(0);

        listViewPreference();

        ApiGetAllRoomList();
    }

    /**
     * 初始化ListView
     */
    private void listViewPreference() {
        ListView mList = pullList.getRefreshView();
        mList.setDivider(new ColorDrawable(getResources().getColor(android.R.color.transparent)));
        mList.setOverscrollFooter(null);
        mList.setOverscrollHeader(null);
        mList.setOverScrollMode(ListView.OVER_SCROLL_NEVER);
        pullList.setPullRefreshEnabled(false);
        pullList.setPullLoadEnabled(false);
        ((FooterLoadingLayout) pullList.getFooterLoadingLayout()).setNoMoreDataText("无更多数据");

        adapter = new MeetingNewRoomStateAdapter(mList, meetingRooms, R.layout.item_meetingapply_roomuser);
        adapter.setOnAddClickListener(onItemActionClick);
        mList.setAdapter(adapter);
    }


    MeetingNewRoomStateAdapter.OnAddClickListener onItemActionClick = new MeetingNewRoomStateAdapter.OnAddClickListener() {

        @Override
        public void onItemClick(String roomName, String startDate, String endDate) {
            loadingDialog.show();
            Map<String, String> params = new HashMap<>();
            params.put("sessionUuid", PreferenceHelper.readString(aty, AppConfig.USER_INFO, AppConfig.SESSION_ID));
            params.put("startDate", time + " " + startDate);
            params.put("endDate", time + " " + endDate);
            for (int i = 0; i < roomList.size(); i++) {
                if (roomName.equals(roomList.get(i).getRoomName())) {
                    params.put("roomId", roomList.get(i).getRoomId());
                }
            }

            presenter.getRoomDetail(params);
        }
    };


    //获取全部会议室
    private void ApiGetAllRoomList() {
        Map<String, String> params = new HashMap<>();
        params.put("sessionUuid", PreferenceHelper.readString(this, AppConfig.USER_INFO, AppConfig.SESSION_ID));
        params.put("pageIndex", "1");
        params.put("pageSize", "9999");
        allRoomPresenter.getAllRoomList(params);
    }

    //获取会议室状态列表
    private void ApiGetRoomStateList(String key, String roomId) {
        loadingDialog.show();
        Map<String, String> params = new HashMap<>();
        params.put("sessionUuid", PreferenceHelper.readString(this, AppConfig.USER_INFO, AppConfig.SESSION_ID));
        params.put("inquireDate", key);
        params.put("use_flag", "");
        params.put("roomId", roomId);
        presenter.getRoomStateList(params);
    }

    //跳转时间
    public void choseCostDay(int choose) {
        tvDate.setText("");
        if (choose == 0) {
            calendar.setTime(new Date());//获取当前时间
        } else {
            calendar.add(Calendar.DATE, choose);
        }
        String str = formatter.format(calendar.getTime());
        time = str;
        tvDate.setText(str);
        ApiGetRoomStateList(str, nowRoomId);
    }

    @Override
    @OnClick({R.id.back, R.id.right, R.id.tv_date, R.id.tv_day_back, R.id.tv_day_next, R.id.tv_day_now,
            R.id.tv_room, R.id.tv_state, R.id.tv_type})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.back:
                finish();
                break;
            case R.id.right:
                loadingDialog.show();
                getSelectTime();

                if (selectRoom == null) {
                    ViewInject.toast("请选择会议室");
                    loadingDialog.dismiss();
                    return;
                }
                if (nowType == 1) {
                    if (TextUtils.isEmpty(selectStartTime) || TextUtils.isEmpty(selectEndTime)) {
                        new ToastDialog(aty, "请选择时间段").show();
                    }

                } else {
                    if (selectTimeBean.size() != 2) {
                        new ToastDialog(aty, "请选择开始时间与结束时间").show();
                        loadingDialog.dismiss();
                        return;
                    }
                    if (!isContinuous) {
                        new ToastDialog(aty, "所选时间点不连续，请重新选择！").show();
                        loadingDialog.dismiss();
                        return;
                    }
                }

                Intent intent = new Intent();
                intent.putExtra("room", selectRoom);
                intent.putExtra("startTime", selectStartTime);
                intent.putExtra("endTime", selectEndTime);
                intent.putExtra("date", tvDate.getText().toString());
                setResult(0x001, intent);
                finish();
                break;
            case R.id.tv_date:
                selectDate();
                break;
            case R.id.tv_day_back:
                choseCostDay(DECREASE_COST_DAY);
                break;
            case R.id.tv_day_next:
                choseCostDay(INCREASE_COST_DAY);
                break;
            case R.id.tv_day_now:
                choseCostDay(0);
                break;
            case R.id.tv_room:
                selectRoom();
                break;
            case R.id.tv_state:
                selectRoomState();
                break;
            case R.id.tv_type:
                selectType();
                break;
        }
    }

    //选择时间
    private void selectDate() {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm", Locale.CHINA);
        String now = sdf.format(calendar.getTime());
        CustomDatePicker customDatePicker = new CustomDatePicker(this, new CustomDatePicker.ResultHandler() {
            @Override
            public void handle(String time) {
                tvDate.setText(time);
                ApiGetRoomStateList(time, nowRoomId);

                try {
                    Date selectDate = (new SimpleDateFormat("yyyy-MM-dd")).parse(time);
                    calendar.setTime(selectDate);
                } catch (ParseException e) {
                    e.printStackTrace();
                }
            }
        }, "2010-01-01 00:00", now); // 初始化日期格式请用：yyyy-MM-dd HH:mm，否则不能正常运行
        customDatePicker.setIsLoop(true); // 不允许循环滚动
        customDatePicker.setCancelable(true);
        customDatePicker.showSpecificDate(true);
        customDatePicker.showSpecificTime(false);
        customDatePicker.show(now);
    }

    //选择会议地点
    private void selectRoom() {
        ActionSheetDialog actionSheetDialog;
        actionSheetDialog = new ActionSheetDialog(this).builder()
                .setCancelable(true)
                .setCanceledOnTouchOutside(true);

        for (int i = 0; i < roomList.size(); i++) {
            actionSheetDialog.addSheetItem(roomList.get(i).getRoomName(), ActionSheetDialog.SheetItemColor.Blue,
                    new ActionSheetDialog.OnSheetItemClickListener() {
                        @Override
                        public void onClick(int which) {
                            nowRoomId = roomList.get(which - 1).getRoomId();
                            tvRoom.setText(roomList.get(which - 1).getRoomName());
                            ApiGetRoomStateList(tvDate.getText().toString(), nowRoomId);
                        }
                    });
        }
        actionSheetDialog.show();
    }

    //选择会议室状态
    private void selectRoomState() {
        ActionSheetDialog actionSheetDialog;
        actionSheetDialog = new ActionSheetDialog(this).builder()
                .setCancelable(true)
                .setCanceledOnTouchOutside(true)
                .addSheetItem("全部", ActionSheetDialog.SheetItemColor.Blue,
                        new ActionSheetDialog.OnSheetItemClickListener() {
                            @Override
                            public void onClick(int which) {
                                tvState.setText("全部");
                                nowUserFlag = 0;
                                ApiGetRoomStateList(tvDate.getText().toString(), nowRoomId);
                            }
                        })
                .addSheetItem("空闲", ActionSheetDialog.SheetItemColor.Blue,
                        new ActionSheetDialog.OnSheetItemClickListener() {
                            @Override
                            public void onClick(int which) {
                                tvState.setText("空闲");
                                nowUserFlag = 1;
                                ApiGetRoomStateList(tvDate.getText().toString(), nowRoomId);
                            }
                        })
                .addSheetItem("占用", ActionSheetDialog.SheetItemColor.Blue,
                        new ActionSheetDialog.OnSheetItemClickListener() {
                            @Override
                            public void onClick(int which) {
                                tvState.setText("占用");
                                nowUserFlag = 2;
                                ApiGetRoomStateList(tvDate.getText().toString(), nowRoomId);
                            }
                        })
                .addSheetItem("锁定", ActionSheetDialog.SheetItemColor.Blue,
                        new ActionSheetDialog.OnSheetItemClickListener() {
                            @Override
                            public void onClick(int which) {
                                tvState.setText("锁定");
                                nowUserFlag = 3;
                                ApiGetRoomStateList(tvDate.getText().toString(), nowRoomId);
                            }
                        });
        actionSheetDialog.show();
    }

    //选择时间类型
    public void selectType() {
        ActionSheetDialog actionSheetDialog;
        actionSheetDialog = new ActionSheetDialog(this).builder()
                .setCancelable(true)
                .setCanceledOnTouchOutside(true)
                .addSheetItem("单个时间", ActionSheetDialog.SheetItemColor.Blue,
                        new ActionSheetDialog.OnSheetItemClickListener() {
                            @Override
                            public void onClick(int which) {
                                tvType.setText("单个时间");
                                nowType = 1;
                                right.setVisibility(View.VISIBLE);
                                for (MeetingNewRoomStateBean item : meetingRooms) {
                                    item.setSelect(false);
                                    for (MeetingNewRoomStateOneBean oneTimeState : item.getOneTimeState()) {
                                        oneTimeState.setSelect(false);
                                    }
                                }
                                adapter.setType(1);
                            }
                        })
                .addSheetItem("连续时间", ActionSheetDialog.SheetItemColor.Blue,
                        new ActionSheetDialog.OnSheetItemClickListener() {
                            @Override
                            public void onClick(int which) {
                                tvType.setText("连续时间");
                                nowType = 2;
                                right.setVisibility(View.VISIBLE);
                                for (MeetingNewRoomStateBean item : meetingRooms) {
                                    item.setSelect(false);
                                    for (MeetingNewRoomStateOneBean oneTimeState : item.getOneTimeState()) {
                                        oneTimeState.setSelect(false);
                                    }
                                }
                                adapter.setType(2);
                            }
                        });
        actionSheetDialog.show();
    }

    @Override
    public void showAllRoomList(BaseEntity<MeetingNewRoomBean> bean) {
        if (bean.getStatus().equals("200")) {
            roomList.clear();
            MeetingNewRoomBean item = new MeetingNewRoomBean();
            item.setRoomId("");
            item.setRoomName("全部");
            roomList.add(item);
            roomList.addAll(bean.getDatas());

            getStateRoomList();
        } else {
            ViewInject.toast(bean.getMessage());
        }
    }

    @Override
    public void showRoomStateList(BaseEntity<String> bean) {
        if (bean.getStatus().equals("200")) {
            meetingRooms.clear();
            getRoomStateDate(bean.getDatas().get(0));

            getStateRoomList();

            adapter.notifyDataSetChanged();
        } else {
            ViewInject.toast(bean.getMessage());
        }
        loadingDialog.dismiss();
    }

    @Override
    public void showRoomDeatail(BaseEntity<MeetingRoomBean> bean) {
        if (loadingDialog.isShowing()) {
            loadingDialog.dismiss();
        }

        if (bean.getStatus().equals("200")) {
            dialog = new MeetingRoomDialog(this);
            dialog.builder()
                    .setContent(bean.getDatas().get(0).getRoomName(), bean.getDatas().get(0).getMeetingName(),
                            bean.getDatas().get(0).getConfigName(), bean.getDatas().get(0).getStartDatetime(),
                            bean.getDatas().get(0).getEndDatetime(), bean.getDatas().get(0).getApplyState() + "", bean.getDatas().get(0).getCreatorName());
            dialog.show();
        } else {
            ViewInject.toast(bean.getMessage());
        }
    }

    //排除自定义会议室
    private void getStateRoomList() {
        if (meetingRooms.size() > 0 && roomList.size() > 0) {
            ArrayList<MeetingNewRoomStateBean> roomStateBean = new ArrayList<>();
            for (int i = 0; i < meetingRooms.size(); i++) {
                for (MeetingNewRoomBean item : roomList) {
                    if (meetingRooms.get(i).getRoomName().equals(item.getRoomName())) {
                        roomStateBean.add(meetingRooms.get(i));
                        break;
                    }
                }
            }
            meetingRooms.clear();
            meetingRooms.addAll(roomStateBean);
        }
    }

    //判断选中时间段
    private void getSelectTime() {
        selectRoom = null;
        selectStartTime = "";
        selectEndTime = "";
        selectTimeBean.clear();
        isContinuous = true;

        if (nowType == 1) {
            for (MeetingNewRoomStateBean item : meetingRooms) {
                if (item.isSelect()) {
                    for (MeetingNewRoomBean room : roomList) {
                        if (room.getRoomName().equals(item.getRoomName())) {
                            selectRoom = room;
                            break;
                        }
                    }

                    for (MeetingNewRoomStateOneBean oneTime : item.getOneTimeState()) {
                        if (oneTime.isSelect()) {
                            getTime(oneTime, 0);
                            break;
                        }
                    }
                    break;
                }
            }
        } else if (nowType == 2) {
            for (MeetingNewRoomStateBean item : meetingRooms) {
                if (item.isSelect()) {
                    for (MeetingNewRoomBean room : roomList) {
                        if (room.getRoomName().equals(item.getRoomName())) {
                            selectRoom = room;
                            break;
                        }
                    }

                    for (MeetingNewRoomStateOneBean oneTime : item.getOneTimeState()) {
                        if (oneTime.isSelect()) {
                            MeetingNewRoomStateOneBean time = new MeetingNewRoomStateOneBean();
                            time.setTimeName(oneTime.getTimeName());
                            time.setTimestate(oneTime.getTimestate());
                            selectTimeBean.add(time);
                            if (selectTimeBean.size() == 2) {
                                break;
                            }
                        }
                    }

                    if (selectTimeBean.size() == 2) {
                        //判断两个时间是否连续
                        int x = Integer.valueOf(selectTimeBean.get(0).getTimeName());
                        int y = Integer.valueOf(selectTimeBean.get(1).getTimeName());
                        if (x < y) {
                            for (; x < y; x++) {
                                for (MeetingNewRoomStateOneBean data : item.getOneTimeState()) {
                                    if ((Integer.valueOf(data.getTimeName()) == x) && (data.getTimestate() != 1)) {
                                        isContinuous = false;
                                        break;
                                    }
                                }
                            }
                        } else {
                            for (; y < x; y++) {
                                for (MeetingNewRoomStateOneBean data : item.getOneTimeState()) {
                                    if ((Integer.valueOf(data.getTimeName()) == y) && (data.getTimestate() != 1)) {
                                        isContinuous = false;
                                        break;
                                    }
                                }
                            }
                        }

                        //取第一个时间的前一段 取后一个时间的后一段
                        if (Integer.valueOf(selectTimeBean.get(0).getTimeName()) < Integer.valueOf(selectTimeBean.get(1).getTimeName())) {
                            getTime(selectTimeBean.get(0), 1);
                            getTime(selectTimeBean.get(1), 2);
                        } else {
                            getTime(selectTimeBean.get(0), 2);
                            getTime(selectTimeBean.get(1), 1);
                        }
                    }


                }
            }
        }
    }

    //0：当前时间段  1：前部时间   2：后部时间
    private void getTime(MeetingNewRoomStateOneBean item, int tag) {
        switch (item.getTimeName()) {
            case "1":
                if (tag == 0) {
                    selectStartTime = "08:00";
                    selectEndTime = "08:30";
                } else if (tag == 1) {
                    selectStartTime = "08:00";
                } else if (tag == 2) {
                    selectEndTime = "08:30";
                }
                break;
            case "2":
                if (tag == 0) {
                    selectStartTime = "08:30";
                    selectEndTime = "09:00";
                } else if (tag == 1) {
                    selectStartTime = "08:30";
                } else if (tag == 2) {
                    selectEndTime = "09:00";
                }
                break;
            case "3":
                if (tag == 0) {
                    selectStartTime = "09:00";
                    selectEndTime = "09:30";
                } else if (tag == 1) {
                    selectStartTime = "09:00";
                } else if (tag == 2) {
                    selectEndTime = "09:30";
                }
                break;
            case "4":
                if (tag == 0) {
                    selectStartTime = "09:30";
                    selectEndTime = "10:00";
                } else if (tag == 1) {
                    selectStartTime = "09:30";
                } else if (tag == 2) {
                    selectEndTime = "10:00";
                }
                break;
            case "5":
                if (tag == 0) {
                    selectStartTime = "10:00";
                    selectEndTime = "10:30";
                } else if (tag == 1) {
                    selectStartTime = "10:00";
                } else if (tag == 2) {
                    selectEndTime = "10:30";
                }
                break;
            case "6":
                if (tag == 0) {
                    selectStartTime = "10:30";
                    selectEndTime = "11:00";
                } else if (tag == 1) {
                    selectStartTime = "10:30";
                } else if (tag == 2) {
                    selectEndTime = "11:00";
                }
                break;
            case "7":
                if (tag == 0) {
                    selectStartTime = "11:00";
                    selectEndTime = "11:30";
                } else if (tag == 1) {
                    selectStartTime = "11:00";
                } else if (tag == 2) {
                    selectEndTime = "11:30";
                }
                break;
            case "8":
                if (tag == 0) {
                    selectStartTime = "11:30";
                    selectEndTime = "12:00";
                } else if (tag == 1) {
                    selectStartTime = "11:30";
                } else if (tag == 2) {
                    selectEndTime = "12:00";
                }
                break;
            case "9":
                if (tag == 0) {
                    selectStartTime = "12:00";
                    selectEndTime = "12:30";
                } else if (tag == 1) {
                    selectStartTime = "12:00";
                } else if (tag == 2) {
                    selectEndTime = "12:30";
                }
                break;
            case "10":
                if (tag == 0) {
                    selectStartTime = "12:30";
                    selectEndTime = "13:00";
                } else if (tag == 1) {
                    selectStartTime = "12:30";
                } else if (tag == 2) {
                    selectEndTime = "13:00";
                }
                break;
            case "11":
                if (tag == 0) {
                    selectStartTime = "13:00";
                    selectEndTime = "13:30";
                } else if (tag == 1) {
                    selectStartTime = "13:00";
                } else if (tag == 2) {
                    selectEndTime = "13:30";
                }
                break;
            case "12":
                if (tag == 0) {
                    selectStartTime = "13:30";
                    selectEndTime = "14:00";
                } else if (tag == 1) {
                    selectStartTime = "13:30";
                } else if (tag == 2) {
                    selectEndTime = "14:00";
                }
                break;
            case "13":
                if (tag == 0) {
                    selectStartTime = "14:00";
                    selectEndTime = "14:30";
                } else if (tag == 1) {
                    selectStartTime = "14:00";
                } else if (tag == 2) {
                    selectEndTime = "14:30";
                }
                break;
            case "14":
                if (tag == 0) {
                    selectStartTime = "14:30";
                    selectEndTime = "15:00";
                } else if (tag == 1) {
                    selectStartTime = "14:30";
                } else if (tag == 2) {
                    selectEndTime = "15:00";
                }
                break;
            case "15":
                if (tag == 0) {
                    selectStartTime = "15:00";
                    selectEndTime = "15:30";
                } else if (tag == 1) {
                    selectStartTime = "15:00";
                } else if (tag == 2) {
                    selectEndTime = "15:30";
                }
                break;
            case "16":
                if (tag == 0) {
                    selectStartTime = "15:30";
                    selectEndTime = "16:00";
                } else if (tag == 1) {
                    selectStartTime = "15:30";
                } else if (tag == 2) {
                    selectEndTime = "16:00";
                }
                break;
            case "17":
                if (tag == 0) {
                    selectStartTime = "16:00";
                    selectEndTime = "16:30";
                } else if (tag == 1) {
                    selectStartTime = "16:00";
                } else if (tag == 2) {
                    selectEndTime = "16:30";
                }
                break;
            case "18":
                if (tag == 0) {
                    selectStartTime = "16:30";
                    selectEndTime = "17:00";
                } else if (tag == 1) {
                    selectStartTime = "16:30";
                } else if (tag == 2) {
                    selectEndTime = "17:00";
                }
                break;
            case "19":
                if (tag == 0) {
                    selectStartTime = "17:00";
                    selectEndTime = "17:30";
                } else if (tag == 1) {
                    selectStartTime = "17:00";
                } else if (tag == 2) {
                    selectEndTime = "17:30";
                }
                break;
            case "20":
                if (tag == 0) {
                    selectStartTime = "17:30";
                    selectEndTime = "18:00";
                } else if (tag == 1) {
                    selectStartTime = "17:30";
                } else if (tag == 2) {
                    selectEndTime = "18:00";
                }
                break;
        }
    }


    //获取解析数据
    private void getRoomStateDate(String bean) {
        try {
            JSONObject data = new JSONObject(bean);
            Iterator<?> iterator = data.keys();
            while (iterator.hasNext()) { // 遍历每个时间段
                String key = (String) iterator.next();

                //切记用optJSONObject();用getJSONObject()在为null的时候会报错哦！！！
                JSONObject ob = data.optJSONObject(key);
                Iterator<?> iterator_2 = ob.keys();
                while (iterator_2.hasNext()) { //遍历每个会议室
                    String roomName = (String) iterator_2.next();
                    int ob_2 = ob.optInt(roomName);

                    int i;
                    for (i = 0; i < meetingRooms.size(); i++) {
                        if (meetingRooms.get(i).getRoomName().equals(roomName)) {
                            MeetingNewRoomStateOneBean item = new MeetingNewRoomStateOneBean();
                            item.setTimeName(key);
                            item.setTimestate(ob_2);
                            meetingRooms.get(i).getOneTimeState().add(item);
                            break;
                        }
                    }

                    if (i == meetingRooms.size()) {
                        MeetingNewRoomStateBean item = new MeetingNewRoomStateBean();
                        item.setRoomName(roomName);

                        ArrayList<MeetingNewRoomStateOneBean> timeState = new ArrayList<>();
                        MeetingNewRoomStateOneBean oneTimeState = new MeetingNewRoomStateOneBean();
                        oneTimeState.setTimeName(key);
                        oneTimeState.setTimestate(ob_2);
                        timeState.add(oneTimeState);
                        item.setOneTimeState(timeState);

                        meetingRooms.add(item);
                    }
                }
            }
            adapter.setUserFlag(nowUserFlag);

        } catch (JSONException e) {
            e.printStackTrace();
        }
    }
}
